package Boundary;

import javax.swing.*;
import javax.swing.text.html.parser.Parser;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import static Control.Control.*;
import static Control.Control.ss;

/**
 * @author Group77
 * @version 4.0
 * @description display an operational page for login
 */
public class Student_Login extends Overall {

    public Student_Login() {
        super("Student_Login");
        panel1.setLayout(new BorderLayout());
        panel1.setBorder(BorderFactory.createEmptyBorder());
        JButton button0 = new JButton("   Exit   ");
        button0.setContentAreaFilled(false);
        button0.setBorder(BorderFactory.createEmptyBorder());
        button0.setFont(new Font("TimesRoman", Font.BOLD, 30));
        JLabel label1 = new JLabel("Learning Journey  ", JLabel.CENTER);
        label1.setFont(new Font("TimesRoman", Font.ITALIC, 30));
        JPanel empty1 = new JPanel();
        empty1.setPreferredSize(new Dimension(100, 10));
        panel1.add(button0, BorderLayout.WEST);
        panel1.add(empty1, BorderLayout.NORTH);
        panel1.add(label1, BorderLayout.EAST);
        Add_Component(jfr, gbl, panel1, gbc, 0, 0, 4, 1, 1, 0);


        button0.addActionListener(
                new ActionListener() {
                    public void actionPerformed(ActionEvent e) {
                        jfr.setVisible(false);

                        jfr.dispose();
                    }
                }
        );


        panel2.setLayout(new BorderLayout());
        panel2.setBorder(BorderFactory.createEmptyBorder());
        JLabel label2 = new JLabel(" Login ");
        label2.setFont(new Font("TimesRoman", Font.BOLD, 40));
        panel2.add(label2, BorderLayout.CENTER);
        Add_Component(jfr, gbl, panel2, gbc, 0, 4, 1, 1, 1, 0);


        panel3.setLayout(new BorderLayout());
        panel3.setBorder(BorderFactory.createEmptyBorder());
        JLabel label3 = new JLabel("Please enter your student's ID and password:", JLabel.CENTER);
        label3.setFont(new Font("TimesRoman", Font.PLAIN, 35));
        panel3.add(label3, BorderLayout.CENTER);
        Add_Component(jfr, gbl, panel3, gbc, 0, 5, 1, 1, 1, 1);


        JLabel label4 = new JLabel("Student_ID:", JLabel.CENTER);
        label4.setFont(new Font("TimesRoman", Font.PLAIN, 24));
        JTextField tf1 = new JTextField(12);
        tf1.setFont(new Font("TimesRoman", Font.PLAIN, 24));
        Box b1 = Box.createHorizontalBox();
        b1.add(label4);
        b1.add(Box.createHorizontalStrut(10));
        b1.add(tf1);
        panel4.add(b1);
        Add_Component(jfr, gbl, panel4, gbc, 0, 6, 1, 1, 1, 0);

        //component 5
        JLabel label5 = new JLabel("          Password:");
        label5.setFont(new Font("TimesRoman", Font.PLAIN, 24));
        JTextField tf2 = new JTextField(12);
        tf2.setFont(new Font("TimesRoman", Font.PLAIN, 24));
        Box b2 = Box.createHorizontalBox();
        b2.add(label5);
        b2.add(Box.createHorizontalStrut(10));
        b2.add(tf2);
        JPanel empty = new JPanel();
        empty.setPreferredSize(new Dimension(-60, 10));
        empty.setBorder(BorderFactory.createEmptyBorder());
        panel5.add(empty);
        panel5.add(b2);
        Add_Component(jfr, gbl, panel5, gbc, 0, 7, 1, 1, 1, 1);

        //component 6
        panel6.setBorder(BorderFactory.createEmptyBorder());
        JButton button3 = new JButton("   Register   ");
        JButton button4 = new JButton("   Confirm   ");
        button3.setBorder(BorderFactory.createRaisedBevelBorder());
        button4.setBorder(BorderFactory.createRaisedBevelBorder());
        button3.setBackground(Color.LIGHT_GRAY);
        button4.setBackground(Color.LIGHT_GRAY);
        button3.setFont(new Font("TimesRoman", Font.BOLD, 30));
        button4.setFont(new Font("TimesRoman", Font.BOLD, 30));
        panel6.add(button3, BorderLayout.CENTER);
        JPanel emp = new JPanel();
        emp.setPreferredSize(new Dimension(700, 10));
        emp.setBorder(BorderFactory.createEmptyBorder());
        panel6.add(emp);
        panel6.add(button4, BorderLayout.CENTER);
        Add_Component(jfr, gbl, panel6, gbc, 0, 8, 0, 1, 1, 1);


        button3.addActionListener(
                new ActionListener() {
                    public void actionPerformed(ActionEvent e) {
                        jfr.setVisible(false);
                        new Register();
                        jfr.dispose();
                    }
                }
        );

        button4.addActionListener(
                new ActionListener() {
                    public void actionPerformed(ActionEvent e) {
                        jfr.setVisible(false);
                        if (ss.student_Login_id(tf1.getText(), tf2.getText()) != null) {
                            student = ss.student_Login_id(tf1.getText(), tf2.getText());
                            new Start(Integer.parseInt(tf1.getText()));
                            jfr.dispose();
                        } else {
                            jfr.setVisible(true);
                            JOptionPane.showMessageDialog(null, "Can not find your account.", "Wrong account", JOptionPane.WARNING_MESSAGE);
                        }
                    }
                }
        );
    }
}